﻿using EFCORE仓储模式.Entites;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

namespace EFCORE仓储模式.Data
{
    public class DataMangermentDbContext : DbContext
    {
        public DataMangermentDbContext(DbContextOptions<DataMangermentDbContext> options) : base(options)
        {
        }

        public DbSet<Player> Player { get; set; }
        public DbSet<Character> Characters { get; set; }


        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {

            //扫码当前程序集下所有实现了IEntityTypeConfiguration接口的类加载配置
            modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());

            modelBuilder.Entity<Player>().HasData(DataSeed.Players);
            modelBuilder.Entity<Character>().HasData(DataSeed.Characters);
        }
    }
}
